package command

import "fmt"

type Person struct {
	name string
	cmd  Command
}

type Command struct {
	person *Person
	method func()
}

func (c *Command) Execute() {
	c.method()
}

func NewCommand(p *Person, m func()) Command {
	return Command{
		person: p,
		method: m,
	}
}

func (p *Person) Buy() {
	fmt.Println(p.name, "is buying something")
	p.cmd.Execute()
}

func (p *Person) Cook() {
	fmt.Println(p.name, "is cooking something")
	p.cmd.Execute()
}

func (p *Person) Wash() {
	fmt.Println(p.name, "is washing something")
	p.cmd.Execute()
}

func (p *Person) Listen() {
	fmt.Println(p.name, "is listening to music")
	// p.cmd.Execute()
}

func (p *Person) Talk() {
	fmt.Println(p.name, "is talking")
	p.cmd.Execute()
}

func NewPerson(name string, cmd Command) Person {
	return Person{
		name: name,
		cmd:  cmd,
	}
}
